package com.hoe.tsb.fraft.event.msg;

//import com.hoe.tsb.fraft.enums.MessageFlag;
import com.hoe.tsb.fraft.Node;
import com.hoe.tsb.fraft.enums.MessageType;
import com.hoe.tsb.fraft.enums.RoleType;
import com.hoe.tsb.fraft.serialize.Serializer;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * FRaft消息实体
 * </p>
 *
 * @author hoe
 * @version 1.0
 * @date 2022/11/21 17:33
 */
@Data
public class FRaftMessage implements Serializable {

    /**
     * 消息类型，占首字节
     */
    private MessageType type;

    /**
     * 消息任期，占其次的3.5个字节
     */
    private int term;

    /**
     * 发出消息的角色，占其次的半字节
     */
    private RoleType roleType;

    /**
     * 消息体
     */
    private byte[] body;

    /**
     * 发送时表示接收者，接收时代表发送者
     */
    private List<Node> nodes;

    public FRaftMessage(MessageType type, int term, RoleType roleType) {
        this(type, term, roleType, null);
    }

    public FRaftMessage(MessageType type, int term, RoleType roleType, byte[] body) {
        this(type, term, roleType, body, null);
    }

    public FRaftMessage(MessageType type, int term, RoleType roleType, byte[] body, List<Node> nodes) {
        this.type = type;
        this.term = term;
        this.roleType = roleType;
        this.body = body;
        this.nodes = nodes;
    }

}
